$(function () {
    $('.erro').hide();
    $('.cText').keyup(function (e) {
        var password = $('.cText').val();
        var numberPassword = $('.number p').html();
        if (password == numberPassword) {
            $('.erro').hide();
        } else if (password !== numberPassword && password.length == 4) {
            $('.erro').show();
        } else {
        }
    });
    flushVerify();
})

function flushVerify() {
    $.ajax({
        url: '/register/verify/' + Math.random(),
        type: 'get',
        dataType: 'json',
        success: function (data) {
            $(".number p").html(data);
        }
    })
}
$("#reNewPassword").on('blur', function () {
    var newPassword=$("#newPassword").val();
    var reNewPassword =$("#reNewPassword").val();
    if(reNewPassword!=newPassword){
        $("#reNewPassword").next(".error").show()
        $(".registerBtn").prop({disabled:true})
    }else{
        $("#reNewPassword").next(".error").hide()
        $(".registerBtn").prop({disabled:false})
    }
})
$(".passwordHande").submit(function () {
    var newPassword=$("#newPassword").val();
    var reNewPassword =$("#reNewPassword").val();
    var username = $("#userName").val();
    var validationNum = $("#validationNum").val()
    var reg = /\d{11}/g;
    if(reNewPassword!=newPassword){
        alert("两次密码不一致");
        return false;
    }
    if (username == "" || username.length != 11 || !reg.test(username)) {
        alert("请输入正确的手机号!");
        return false;
    }
    if(validationNum.length==0){
        alert("请输入验证码")
        return false;
    }
})

function validate() {
    var username = $("#userName").val();
    var reg = /\d{11}/g;
    if (username == "" || username.length != 11 || !reg.test(username)) {
        alert("请输入正确的手机号!");
    } else {
        $.ajax({
            url: '/register/sendValidateNum',
            type: "POST",
            data: {userName: username},
            success: function () {
                $(".getValidationNum").attr("href", "javascript:void(0)");
                var endTime = 60;
                var set = setInterval(function () {
                    if (endTime > 0) {
                        $(".getValidationNum").html("重新获取验证码(" + endTime + ")")
                        endTime -= 1

                    } else {
                        $(".getValidationNum").html("重新获取验证码").attr("href", "javascript:validate()")
                        clearInterval(set)
                    }
                }, 1000);

            }
        });
    }
}
function protocol(){
    document.getElementById("protocolPopup").style.display = "block"
}
function closeprotocol(){
    document.getElementById("protocolPopup").style.display = "none"
}
$(".spText").on('blur', function () {
    if($(this).val().length!=6){
        $(this).next(".error").show()
        $(".registerBtn").prop({disabled:"disabled"})
    }else{
        $(this).next(".error").hide()
        $(".registerBtn").removeAttr("disabled")
    }
})
$("#reNewUPassword").on('blur', function () {
    var newPassword=$("#newUPassword").val();
    var reNewPassword =$("#reNewUPassword").val();
    console.log(reNewPassword!=newPassword)
    if(reNewPassword!=newPassword){
        $("#reNewUPassword").next(".error").show()
        $(".registerBtn").prop({disabled:"disabled"})
    }else{
        $("#reNewUPassword").next(".error").hide()
        $(".registerBtn").removeAttr("disabled")
    }
})